package com.example.myapplication.ui.components

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.clickable
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp

/**
 * 长按操作底部抽屉菜单
 */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ActionBottomSheet(
    onDismiss: () -> Unit,
    title: String,
    actions: List<ActionItem>,
    onEditItemClick: () -> Unit = {},
    onMoveItemClick: () -> Unit = {}
) {
    ModalBottomSheet(
        onDismissRequest = onDismiss,
        dragHandle = { BottomSheetDefaults.DragHandle() }
    ) {
        Column(
            modifier = Modifier
                .fillMaxWidth()
                .padding(16.dp)
        ) {
            Text(
                text = title,
                style = MaterialTheme.typography.titleLarge,
                modifier = Modifier.padding(bottom = 16.dp)
            )
            
            actions.forEach { action ->
                Row(
                    modifier = Modifier
                        .fillMaxWidth()
                        .clickable {
                            onDismiss()
                            action.onClick()
                        }
                        .padding(vertical = 12.dp),
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Icon(
                        imageVector = action.icon,
                        contentDescription = action.title,
                        modifier = Modifier.size(24.dp),
                        tint = if (action.isDestructive) MaterialTheme.colorScheme.error 
                              else MaterialTheme.colorScheme.onSurface
                    )
                    Spacer(modifier = Modifier.width(16.dp))
                    Text(
                        text = action.title,
                        style = MaterialTheme.typography.bodyLarge,
                        color = if (action.isDestructive) MaterialTheme.colorScheme.error 
                               else MaterialTheme.colorScheme.onSurface
                    )
                }
            }
            
            Spacer(modifier = Modifier.height(32.dp))
        }
    }
}

/**
 * 操作项数据类
 */
data class ActionItem(
    val title: String,
    val icon: ImageVector,
    val onClick: () -> Unit,
    val isDestructive: Boolean = false,
    val onEditItemClick: (() -> Unit)? = null,
    val onMoveItemClick: (() -> Unit)? = null
)

/**
 * 预定义的储物空间操作
 */
object StorageSpaceActions {
    fun getActions(
        onEdit: () -> Unit,
        onDelete: () -> Unit
    ): List<ActionItem> = listOf(
        ActionItem(
            title = "编辑",
            icon = Icons.Default.Edit,
            onClick = onEdit
        ),
        ActionItem(
            title = "删除",
            icon = Icons.Default.Delete,
            onClick = onDelete,
            isDestructive = true
        )
    )
}

/**
 * 预定义的物品操作
 */
object StorageItemActions {
    fun getActions(
        onMove: () -> Unit,
        onEdit: () -> Unit,
        onDelete: () -> Unit
    ): List<ActionItem> = listOf(
        ActionItem(
            title = "迁移",
            icon = Icons.Default.DriveFileMove,
            onClick = onMove
        ),
        ActionItem(
            title = "编辑",
            icon = Icons.Default.Edit,
            onClick = onEdit
        ),
        ActionItem(
            title = "删除",
            icon = Icons.Default.Delete,
            onClick = onDelete,
            isDestructive = true
        )
    )
}